package com.afc.struts.utils;

import javax.servlet.http.HttpServletRequest;

import com.afc.struts.ActionServlet;

public class Report
{
  static public void error(String aTitle, String aMessage, HttpServletRequest aRequest)
  {
    String message = "";
    String oldMessage = (String)aRequest.getAttribute(ActionServlet.ERROR_REQUEST_ATTRIBUTE_NAME);
    if (oldMessage != null)
    {
      message += oldMessage;
    }
    if (aTitle != null)
    {
      message += "<div style=\"color:red; font-weight:bold\">" + aTitle + " : </div>";
    }
    message += "<div style=\"color:red;\">" + aMessage + "</div>";
    aRequest.setAttribute(ActionServlet.ERROR_REQUEST_ATTRIBUTE_NAME, message);
  }

  static public void error(String aTitle, String aMessage, Throwable aThrowable, HttpServletRequest aRequest)
  {
    error(aTitle, aMessage, aRequest);
    Throwable throwable = aThrowable;
    error(null, throwable.getMessage(), aRequest);
    while (throwable.getCause() != null)
    {
      throwable = throwable.getCause();
      error(null, throwable.getMessage(), aRequest);
    }
    aThrowable.printStackTrace();
  }
}
